const { v4: uuidv4 } = require('uuid');

module.exports = {
  up: async (queryInterface) => {
    const now = new Date();

    // 检查是否已存在配置
    const [existingConfigs] = await queryInterface.sequelize.query(
      `SELECT id FROM oss_configs WHERE name = '默认MinIO配置' LIMIT 1`
    );

    if (existingConfigs && existingConfigs.length > 0) {
      console.log('✅ OSS配置已存在');
      return;
    }

    // 添加默认的 MinIO 配置
    await queryInterface.bulkInsert('oss_configs', [
      {
        id: uuidv4(),
        tenant_id: null, // 全局配置
        name: '默认MinIO配置',
        type: 'minio',
        endpoint: 'minion.xlcig.cn',
        port: 443,
        use_ssl: true,
        access_key: 'admin',
        secret_key: 'StrongPass123!',
        bucket_name: 'xux',
        region: 'us-east-1',
        is_default: true,
        is_active: true,
        max_file_size: 50,
        allowed_types: '',
        remark: '默认的MinIO存储配置',
        created_at: now,
        updated_at: now,
      },
    ]);

    console.log('✅ 默认OSS配置添加成功');
  },

  down: async (queryInterface) => {
    await queryInterface.bulkDelete('oss_configs', {
      name: '默认MinIO配置'
    }, {});
  },
};

